package com.hc.window;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;

import com.hc.util.CommonData;
import com.hc.util.ImageUtil;

public class LuJingPanel extends JDialog {
	
	private LuJingMapPanel pathMapPanel ;
	private JScrollPane scrollPane;
	public LuJingPanel() {
		getContentPane().setLayout(new BorderLayout(0, 0));
		
		if(1800<CommonData.screenWidth&&1020<CommonData.screenHeight){
			
			this.setSize(1800, 1000);
		}else if(1800>CommonData.screenWidth&&1020<CommonData.screenHeight){
			this.setSize(CommonData.screenWidth, 1000);
		}else if(1800<CommonData.screenWidth&&1020>CommonData.screenHeight){
			this.setSize(1800, CommonData.screenHeight-20);
		}
		
	
		this.setResizable(false);
		this.setModal(true);
		
		JPanel panel = new JPanel();
		getContentPane().add(panel, BorderLayout.NORTH);
		panel.setLayout(new BorderLayout(0, 0));
		
		JPanel panel_1 = new JPanel();
		panel_1.setPreferredSize(new Dimension(100, 35));
		panel.add(panel_1, BorderLayout.EAST);
		panel_1.setLayout(null);
		
		JButton button = new JButton("\u8BBE\u7F6E");
		button.setBounds(0, 0, 64, 35);
		panel_1.add(button);
		button.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				
				
				if(pathMapPanel.lineSettingPanel.isVisible()){
					
					pathMapPanel.lineSettingPanel.setVisible(false);
				}else{
				
				JScrollBar jsVB = scrollPane.getVerticalScrollBar();
				int jsY = 0 ;
				if (jsVB != null) {
					jsY = jsVB.getValue();
				}
				JScrollBar jsHB = scrollPane.getHorizontalScrollBar();
				int jsX = 0;
				if (null != jsHB) {
					jsX = jsHB.getValue();
					
				}
				
				pathMapPanel.lineSettingPanel.setBounds(1035+jsX, jsY, 719, 500);
				pathMapPanel.lineSettingPanel.setVisible(true);
				}
			}
		});
		
		JPanel panel_2 = new JPanel();
		panel.add(panel_2, BorderLayout.CENTER);
		
		JLabel label = new JLabel("\u8DEF\u5F84\u8F68\u8FF9");
		panel_2.add(label);
		scrollPane = new JScrollPane();
		scrollPane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {
			
			@Override
			public void adjustmentValueChanged(AdjustmentEvent e) {
			
				scrollPanelChanged();
				
			}
		});
		scrollPane.getHorizontalScrollBar().addAdjustmentListener(new AdjustmentListener() {
			
			@Override
			public void adjustmentValueChanged(AdjustmentEvent e) {
				scrollPanelChanged();
				
			}
		});
		getContentPane().add(scrollPane, BorderLayout.CENTER);
		
		pathMapPanel = new LuJingMapPanel(ImageUtil.backMap);
		pathMapPanel.setPreferredSize(new Dimension(ImageUtil.backMap.getWidth(null), ImageUtil.backMap.getHeight(null)));
		scrollPane.setViewportView(pathMapPanel);
		
		this.setLocationRelativeTo(getOwner());
		this.setVisible(true);
		
//		this.addWindowListener(new WindowAdapter() {
//			
//			
//			public void windowDeactivated(WindowEvent e) {
//				
//			
//				dispose();
//
//			};
//		}
//		);
		
		
		
		
	}

	public void scrollPanelChanged() {
		if(pathMapPanel.lineSettingPanel.isVisible()){
			
			JScrollBar jsVB = scrollPane.getVerticalScrollBar();
			int jsY = 0 ;
			if (jsVB != null) {
				jsY = jsVB.getValue();
			}
			JScrollBar jsHB = scrollPane.getHorizontalScrollBar();
			int jsX = 0;
			if (null != jsHB) {
				jsX = jsHB.getValue();
				
			}
			
			pathMapPanel.lineSettingPanel.setBounds(1035+jsX, jsY, 719, 500);
			repaint();
		}
		
	}

	
	
}
